#ifndef _ANDROID_TO_LINUX_KEY_MAP
#define _ANDROID_TO_LINUX_KEY_MAP
#include <linux/input.h>
#include <vector>

namespace Marco
{
   namespace AndroidKeys
   {
      const int KEYCODE_UNKNOWN         = 0;
      const int KEYCODE_SOFT_LEFT       = 1;
      const int KEYCODE_SOFT_RIGHT      = 2;
      const int KEYCODE_HOME            = 3;
      const int KEYCODE_BACK            = 4;
      const int KEYCODE_CALL            = 5;
      const int KEYCODE_ENDCALL         = 6;
      const int KEYCODE_0               = 7;
      const int KEYCODE_1               = 8;
      const int KEYCODE_2               = 9;
      const int KEYCODE_3               = 10;
      const int KEYCODE_4               = 11;
      const int KEYCODE_5               = 12;
      const int KEYCODE_6               = 13;
      const int KEYCODE_7               = 14;
      const int KEYCODE_8               = 15;
      const int KEYCODE_9               = 16;
      const int KEYCODE_STAR            = 17;
      const int KEYCODE_POUND           = 18;
      const int KEYCODE_DPAD_UP         = 19;
      const int KEYCODE_DPAD_DOWN       = 20;
      const int KEYCODE_DPAD_LEFT       = 21;
      const int KEYCODE_DPAD_RIGHT      = 22;
      const int KEYCODE_DPAD_CENTER     = 23;
      const int KEYCODE_VOLUME_UP       = 24;
      const int KEYCODE_VOLUME_DOWN     = 25;
      const int KEYCODE_POWER           = 26;
      const int KEYCODE_CAMERA          = 27;
      const int KEYCODE_CLEAR           = 28;
      const int KEYCODE_A               = 29;
      const int KEYCODE_B               = 30;
      const int KEYCODE_C               = 31;
      const int KEYCODE_D               = 32;
      const int KEYCODE_E               = 33;
      const int KEYCODE_F               = 34;
      const int KEYCODE_G               = 35;
      const int KEYCODE_H               = 36;
      const int KEYCODE_I               = 37;
      const int KEYCODE_J               = 38;
      const int KEYCODE_K               = 39;
      const int KEYCODE_L               = 40;
      const int KEYCODE_M               = 41;
      const int KEYCODE_N               = 42;
      const int KEYCODE_O               = 43;
      const int KEYCODE_P               = 44;
      const int KEYCODE_Q               = 45;
      const int KEYCODE_R               = 46;
      const int KEYCODE_S               = 47;
      const int KEYCODE_T               = 48;
      const int KEYCODE_U               = 49;
      const int KEYCODE_V               = 50;
      const int KEYCODE_W               = 51;
      const int KEYCODE_X               = 52;
      const int KEYCODE_Y               = 53;
      const int KEYCODE_Z               = 54;
      const int KEYCODE_COMMA           = 55;
      const int KEYCODE_PERIOD          = 56;
      const int KEYCODE_ALT_LEFT        = 57;
      const int KEYCODE_ALT_RIGHT       = 58;
      const int KEYCODE_SHIFT_LEFT      = 59;
      const int KEYCODE_SHIFT_RIGHT     = 60;
      const int KEYCODE_TAB             = 61;
      const int KEYCODE_SPACE           = 62;
      const int KEYCODE_SYM             = 63;
      const int KEYCODE_EXPLORER        = 64;
      const int KEYCODE_ENVELOPE        = 65;
      const int KEYCODE_ENTER           = 66;
      const int KEYCODE_DEL             = 67;
      const int KEYCODE_GRAVE           = 68;
      const int KEYCODE_MINUS           = 69;
      const int KEYCODE_EQUALS          = 70;
      const int KEYCODE_LEFT_BRACKET    = 71;
      const int KEYCODE_RIGHT_BRACKET   = 72;
      const int KEYCODE_BACKSLASH       = 73;
      const int KEYCODE_SEMICOLON       = 74;
      const int KEYCODE_APOSTROPHE      = 75;
      const int KEYCODE_SLASH           = 76;
      const int KEYCODE_AT              = 77;
      const int KEYCODE_NUM             = 78;
      const int KEYCODE_HEADSETHOOK     = 79;
      const int KEYCODE_FOCUS           = 80;   // *Camera* focus
      const int KEYCODE_PLUS            = 81;
      const int KEYCODE_MENU            = 82;
      const int KEYCODE_NOTIFICATION    = 83;
      const int KEYCODE_SEARCH          = 84;
      const int KEYCODE_MEDIA_PLAY_PAUSE= 85;
      const int KEYCODE_MEDIA_STOP      = 86;
      const int KEYCODE_MEDIA_NEXT      = 87;
      const int KEYCODE_MEDIA_PREVIOUS  = 88;
      const int KEYCODE_MEDIA_REWIND    = 89;
      const int KEYCODE_MEDIA_FAST_FORWARD = 90;
      const int KEYCODE_MUTE            = 91;

      namespace Modifiers
      {
         int META_ALT_LEFT_ON = 0x00000010;
         int META_ALT_MASK = 0x00000032;
         int META_ALT_ON = 0x00000002;
         int META_ALT_RIGHT_ON = 0x00000020;
         int META_CAPS_LOCK_ON = 0x00100000;
         int META_CTRL_LEFT_ON = 0x00002000;
         int META_CTRL_MASK = 0x00007000;
         int META_CTRL_ON = 0x00001000;
         int META_CTRL_RIGHT_ON = 0x00004000;
         int META_FUNCTION_ON = 0x00000008;
         int META_META_LEFT_ON = 0x00020000;
         int META_META_MASK = 0x00070000;
         int META_META_ON = 0x00010000;
         int META_META_RIGHT_ON = 0x00040000;
         int META_NUM_LOCK_ON = 0x00200000;
         int META_SCROLL_LOCK_ON = 0x00400000;
         int META_SHIFT_LEFT_ON = 0x00000040;
         int META_SHIFT_MASK = 0x000000C1;
         int META_SHIFT_ON = 0x00000001;
         int META_SHIFT_RIGHT_ON = 0x00000080;
         int META_SYM_ON = 0x00000004;
      }
   }

   class AndroidToLinuxKeyMap
   {
      public:
         AndroidToLinuxKeyMap(){}
         ~AndroidToLinuxKeyMap(){}

         static int ToLinux(int androidCode)
         {
            int linuxKey = KEY_RESERVED;
            switch(androidCode)
            {
               case(AndroidKeys::KEYCODE_UNKNOWN):
                  linuxKey = KEY_RESERVED;
                  break;
               case(AndroidKeys::KEYCODE_SOFT_LEFT):
                  break;
               case(AndroidKeys::KEYCODE_SOFT_RIGHT):
                  break;
               case(AndroidKeys::KEYCODE_HOME):
                  linuxKey = KEY_HOME;
                  break;
               case(AndroidKeys::KEYCODE_BACK):
                  linuxKey = KEY_BACK;
                  break;
               case(AndroidKeys::KEYCODE_CALL):
                  //linuxKey = KEY_CALL;
                  break;
               case(AndroidKeys::KEYCODE_ENDCALL):
                  //linuxKey = KEY_ENDCALL;
                  break;
               case(AndroidKeys::KEYCODE_0):
                  linuxKey = KEY_0;
                  break;
               case(AndroidKeys::KEYCODE_1):
                  linuxKey = KEY_1;
                  break;
               case(AndroidKeys::KEYCODE_2):
                  linuxKey = KEY_2;
                  break;
               case(AndroidKeys::KEYCODE_3):
                  linuxKey = KEY_3;
                  break;
               case(AndroidKeys::KEYCODE_4):
                  linuxKey = KEY_4;
                  break;
               case(AndroidKeys::KEYCODE_5):
                  linuxKey = KEY_5;
                  break;
               case(AndroidKeys::KEYCODE_6):
                  linuxKey = KEY_6;
                  break;
               case(AndroidKeys::KEYCODE_7):
                  linuxKey = KEY_7;
                  break;
               case(AndroidKeys::KEYCODE_8):
                  linuxKey = KEY_8;
                  break;
               case(AndroidKeys::KEYCODE_9):
                  linuxKey = KEY_9;
                  break;
               case(AndroidKeys::KEYCODE_STAR):
                  //linuxKey = KEY_STAR;
                  break;
               case(AndroidKeys::KEYCODE_POUND):
                  //linuxKey = KEY_POUND;
                  break;
               case(AndroidKeys::KEYCODE_DPAD_UP):
                  linuxKey = KEY_UP;
                  break;
               case(AndroidKeys::KEYCODE_DPAD_DOWN):
                  linuxKey = KEY_DOWN;
                  break;
               case(AndroidKeys::KEYCODE_DPAD_LEFT):
                  linuxKey = KEY_LEFT;
                  break;
               case(AndroidKeys::KEYCODE_DPAD_RIGHT):
                  linuxKey = KEY_RIGHT;
                  break;
               case(AndroidKeys::KEYCODE_DPAD_CENTER):
                  //linuxKey = BTN_LEFT;
                  break;
               case(AndroidKeys::KEYCODE_VOLUME_UP):
                  linuxKey = KEY_VOLUMEUP;
                  break;
               case(AndroidKeys::KEYCODE_VOLUME_DOWN):
                  linuxKey = KEY_VOLUMEDOWN;
                  break;
               case(AndroidKeys::KEYCODE_POWER):
                  //linuxKey = KEY_POWER;
                  break;
               case(AndroidKeys::KEYCODE_CAMERA):
                  linuxKey = KEY_CAMERA;
                  break;
               case(AndroidKeys::KEYCODE_CLEAR):
                  linuxKey = KEY_CLEAR;
                  break;
               case(AndroidKeys::KEYCODE_A):
                  linuxKey = KEY_A;
                  break;
               case(AndroidKeys::KEYCODE_B):
                  linuxKey = KEY_B;
                  break;
               case(AndroidKeys::KEYCODE_C):
                  linuxKey = KEY_C;
                  break;
               case(AndroidKeys::KEYCODE_D):
                  linuxKey = KEY_D;
                  break;
               case(AndroidKeys::KEYCODE_E):
                  linuxKey = KEY_E;
                  break;
               case(AndroidKeys::KEYCODE_F):
                  linuxKey = KEY_F;
                  break;
               case(AndroidKeys::KEYCODE_G):
                  linuxKey = KEY_G;
                  break;
               case(AndroidKeys::KEYCODE_H):
                  linuxKey = KEY_H;
                  break;
               case(AndroidKeys::KEYCODE_I):
                  linuxKey = KEY_I;
                  break;
               case(AndroidKeys::KEYCODE_J):
                  linuxKey = KEY_J;
                  break;
               case(AndroidKeys::KEYCODE_K):
                  linuxKey = KEY_K;
                  break;
               case(AndroidKeys::KEYCODE_L):
                  linuxKey = KEY_L;
                  break;
               case(AndroidKeys::KEYCODE_M):
                  linuxKey = KEY_M;
                  break;
               case(AndroidKeys::KEYCODE_N):
                  linuxKey = KEY_N;
                  break;
               case(AndroidKeys::KEYCODE_O):
                  linuxKey = KEY_O;
                  break;
               case(AndroidKeys::KEYCODE_P):
                  linuxKey = KEY_P;
                  break;
               case(AndroidKeys::KEYCODE_Q):
                  linuxKey = KEY_Q;
                  break;
               case(AndroidKeys::KEYCODE_R):
                  linuxKey = KEY_R;
                  break;
               case(AndroidKeys::KEYCODE_S):
                  linuxKey = KEY_S;
                  break;
               case(AndroidKeys::KEYCODE_T):
                  linuxKey = KEY_T;
                  break;
               case(AndroidKeys::KEYCODE_U):
                  linuxKey = KEY_U;
                  break;
               case(AndroidKeys::KEYCODE_V):
                  linuxKey = KEY_V;
                  break;
               case(AndroidKeys::KEYCODE_W):
                  linuxKey = KEY_W;
                  break;
               case(AndroidKeys::KEYCODE_X):
                  linuxKey = KEY_X;
                  break;
               case(AndroidKeys::KEYCODE_Y):
                  linuxKey = KEY_Y;
                  break;
               case(AndroidKeys::KEYCODE_Z):
                  linuxKey = KEY_Z;
                  break;
               case(AndroidKeys::KEYCODE_COMMA):
                  linuxKey = KEY_COMMA;
                  break;
               case(AndroidKeys::KEYCODE_PERIOD):
                  linuxKey = KEY_DOT;
                  break;
               case(AndroidKeys::KEYCODE_ALT_LEFT):
                  linuxKey = KEY_LEFTALT;
                  break;
               case(AndroidKeys::KEYCODE_ALT_RIGHT):
                  linuxKey = KEY_RIGHTALT;
                  break;
               case(AndroidKeys::KEYCODE_SHIFT_LEFT):
                  linuxKey = KEY_LEFTSHIFT;
                  break;
               case(AndroidKeys::KEYCODE_SHIFT_RIGHT):
                  linuxKey = KEY_RIGHTSHIFT;
                  break;
               case(AndroidKeys::KEYCODE_TAB):
                  linuxKey = KEY_TAB;
                  break;
               case(AndroidKeys::KEYCODE_SPACE):
                  linuxKey = KEY_SPACE;
                  break;
               case(AndroidKeys::KEYCODE_SYM):
                  //linuxKey = KEY_SYM;
                  break;
               case(AndroidKeys::KEYCODE_EXPLORER):
                  //linuxKey = KEY_EXPLORER;
                  break;
               case(AndroidKeys::KEYCODE_ENVELOPE):
                  //linuxKey = KEY_ENVELOPE;
                  break;
               case(AndroidKeys::KEYCODE_ENTER):
                  linuxKey = KEY_ENTER;
                  break;
               case(AndroidKeys::KEYCODE_DEL):
                  linuxKey = KEY_DELETE;
                  break;
               case(AndroidKeys::KEYCODE_GRAVE):
                  linuxKey = KEY_GRAVE;
                  break;
               case(AndroidKeys::KEYCODE_MINUS):
                  linuxKey = KEY_MINUS;
                  break;
               case(AndroidKeys::KEYCODE_EQUALS):
                  linuxKey = KEY_EQUAL;
                  break;
               case(AndroidKeys::KEYCODE_LEFT_BRACKET):
                  linuxKey = KEY_LEFTBRACE;
                  break;
               case(AndroidKeys::KEYCODE_RIGHT_BRACKET):
                  linuxKey = KEY_RIGHTBRACE;
                  break;
               case(AndroidKeys::KEYCODE_BACKSLASH):
                  linuxKey = KEY_BACKSLASH;
                  break;
               case(AndroidKeys::KEYCODE_SEMICOLON):
                  linuxKey = KEY_SEMICOLON;
                  break;
               case(AndroidKeys::KEYCODE_APOSTROPHE):
                  linuxKey = KEY_APOSTROPHE;
                  break;
               case(AndroidKeys::KEYCODE_SLASH):
                  linuxKey = KEY_SLASH;
                  break;
               case(AndroidKeys::KEYCODE_AT):
                  //linuxKey = KEY_AT;
                  break;
               case(AndroidKeys::KEYCODE_NUM):
                  linuxKey = KEY_LEFTALT;
                  break;
               case(AndroidKeys::KEYCODE_HEADSETHOOK):
                  //linuxKey = KEY_HEADSETHOOK;
                  break;
               case(AndroidKeys::KEYCODE_FOCUS):
                  //linuxKey = KEY_FOCUS;
                  break;
               case(AndroidKeys::KEYCODE_PLUS):
                  linuxKey = KEY_KPPLUS;
                  break;
               case(AndroidKeys::KEYCODE_MENU):
                  linuxKey = BTN_RIGHT;
                  break;
               case(AndroidKeys::KEYCODE_NOTIFICATION):
                  //linuxKey = KEY_NOTIFICATION;
                  break;
               case(AndroidKeys::KEYCODE_SEARCH):
                  linuxKey = KEY_SEARCH;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_PLAY_PAUSE):
                  linuxKey = KEY_PLAYPAUSE;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_STOP):
                  linuxKey = KEY_STOPCD;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_NEXT):
                  linuxKey = KEY_NEXTSONG;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_PREVIOUS):
                  linuxKey = KEY_PREVIOUSSONG;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_REWIND):
                  linuxKey = KEY_REWIND;
                  break;
               case(AndroidKeys::KEYCODE_MEDIA_FAST_FORWARD):
                  linuxKey = KEY_FORWARD;
                  break;
               case(AndroidKeys::KEYCODE_MUTE):
                  linuxKey = KEY_MUTE;
                  break;
               default:
                  break;
            }
            return(linuxKey);
         }

         static std::vector<int> GetModifier(int event)
         {
            std::vector<int> modifiers;
            if(event > 1)
            {
               event = event - 1;
               if((event & AndroidKeys::Modifiers::META_ALT_ON) ||
                  (event & AndroidKeys::Modifiers::META_ALT_LEFT_ON))
               {
                  modifiers.push_back(KEY_LEFTALT);
               }

               if(event & AndroidKeys::Modifiers::META_ALT_RIGHT_ON)
               {
                  modifiers.push_back(KEY_RIGHTALT);
               }

               if((event & AndroidKeys::Modifiers::META_CTRL_ON) ||
                  (event & AndroidKeys::Modifiers::META_CTRL_LEFT_ON))
               {
                  modifiers.push_back(KEY_LEFTCTRL);
               }

               if(event & AndroidKeys::Modifiers::META_CTRL_RIGHT_ON)
               {
                  modifiers.push_back(KEY_RIGHTCTRL);
               }

               if((event & AndroidKeys::Modifiers::META_SHIFT_ON) ||
                  (event & AndroidKeys::Modifiers::META_SHIFT_LEFT_ON))
               {
                  modifiers.push_back(KEY_LEFTSHIFT);
               }

               if(event & AndroidKeys::Modifiers::META_SHIFT_RIGHT_ON)
               {
                  modifiers.push_back(KEY_RIGHTSHIFT);
               }

               if((event & AndroidKeys::Modifiers::META_META_ON) ||
                  (event & AndroidKeys::Modifiers::META_META_LEFT_ON))
               {
                  modifiers.push_back(KEY_LEFTMETA);
               }

               if(event & AndroidKeys::Modifiers::META_META_RIGHT_ON)
               {
                  modifiers.push_back(KEY_RIGHTMETA);
               }

               if(event & AndroidKeys::Modifiers::META_CAPS_LOCK_ON)
               {
                  modifiers.push_back(KEY_CAPSLOCK);
               }

               if(event & AndroidKeys::Modifiers::META_FUNCTION_ON)
               {
                  //modifiers.push_back(KEY_CAPSLOCK);
               }

               if(event & AndroidKeys::Modifiers::META_NUM_LOCK_ON)
               {
                  modifiers.push_back(KEY_NUMLOCK);
               }

               if(event & AndroidKeys::Modifiers::META_SCROLL_LOCK_ON)
               {
                  modifiers.push_back(KEY_SCROLLLOCK);
               }
            }
            return(modifiers);
         }
   };
}

#endif
